<?php
# This file is part of "Central heating manager".

# "Central heating manager" is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# "Central heating manager" is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with "Central heating manager".  If not, see <http://www.gnu.org/licenses/>.



function setMode($zoneid, $modeid){
	echo $modeid;
	
	// Récupération des infos
	$relais = getRelais($zoneid);
	$mode = getModes(array('modeid' => $modeid));
	
	print_r($relais);
	print_r($mode);
	
	// Activation des relais
	setRelai($relais['pos'], $mode['ordrePos']);
	setRelai($relais['neg'], $mode['ordreNeg']);
	
	
	// Temporisation => retour à 0 après la tempo
	if ($mode['ordreTempo'] > 0){
		sleep($mode['ordreTempo']);
		setRelai($relais['pos'], 0);
		setRelai($relais['neg'], 0);
		
	}
	
}

// Fonction pour modifier l'état d'un relai
function setRelai($relaiPin, $etat){
	$setmodecmd = 'gpio mode '.$relaiPin.' out';
	$setetatcmd = 'gpio write '.$relaiPin.' '.$etat;
	
echo ($setmodecmd."\n");	
echo ($setetatcmd."\n");	

	exec($setmodecmd);
	exec($setetatcmd);
}